local chushi = fk.CreateSkill{
  name = "hanqing__chushi",
  tags = { "HQ.Reform" },
}

Fk:loadTranslationTable{
  ["hanqing__chushi"] = "处势",
  [":hanqing__chushi"] = "<a href='hanqing_reform_skill'>变革技</a>，当你造成或受到伤害时，你可以令一名本回合未选择过的角色获得"..
  "<a href=':shendao_twelve_chapters'>《十二论》</a>。",

  ["#hanqing__chushi-choose"] = "处势：你可以令一名角色获得《十二论》",
}

local spec = {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(chushi.name) and
      player.room:getCardArea(player.room:getBanner(chushi.name)[1]) == Card.Void and
      table.find(player.room.alive_players, function (p)
        return not table.contains(player:getTableMark("hanqing__chushi-turn"), p.id)
      end)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
      return not table.contains(player:getTableMark("hanqing__chushi-turn"), p.id)
    end)
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = targets,
      skill_name = chushi.name,
      prompt = "#hanqing__chushi-choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:addTableMark(player, "hanqing__chushi-turn", to.id)
    room:moveCardTo(room:getBanner(chushi.name), Card.PlayerHand, to, fk.ReasonJustMove, chushi.name, nil, true, player)
  end,
}
chushi:addEffect(fk.DamageCaused, spec)
chushi:addEffect(fk.DamageInflicted, spec)

chushi:addAcquireEffect(function (self, player, is_start)
  local room = player.room
  room:addSkill("shendao_twelve_chapters_skill")
  if not room:getBanner(chushi.name) then
    local card = room:printCard("shendao_twelve_chapters")
    card.type = 114514
    room:setBanner(chushi.name, {card.id})
  end
end)

return chushi
